package com.zmn.oms.admin.controller.common;

import com.zmn.consts.GlobalConsts;
import com.zmn.oms.admin.controller.order.OrderBaseController;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.common.exception.OmsBaseException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 类描述：渠道
 *
 * @author liuying
 * @date 2018/11/21 15:36
 */
@Controller
@RequestMapping("/channel")
public class ChannelController extends OrderBaseController {

	/**
	 * 获取二级渠道列表（模糊查询）有权限
	 */
	@RequestMapping(value = "list/query", method = RequestMethod.GET)
	@ResponseBody
	public ResultDTO list(@RequestParam(required = false) Integer plat, @RequestParam(required = false) String keyword, @RequestParam(required = false) List<Integer> parentIds) {
		return ResultDTO.success(super.getAllChannelList(plat, keyword, GlobalConsts.LEVEL_2, parentIds));
	}

	/**
	 * 获取二级渠道列表（模糊查询）有权限
	 */
	@RequestMapping(value = "permit/list/query", method = RequestMethod.GET)
	@ResponseBody
	public ResultDTO permitList(@RequestParam(required = false) Integer plat, @RequestParam(required = false) String keyword, @RequestParam(required = false) List<Integer> parentIds) {
		return ResultDTO.success(super.getAllChannelListByPermit(plat, keyword, GlobalConsts.LEVEL_2, parentIds));
	}

	/**
	 * 获取一级渠道列表（模糊查询）有权限
	 */
	@RequestMapping(value = "/one/permit/list/query", method = RequestMethod.GET)
	@ResponseBody
	public ResultDTO permitPrimaryList(@RequestParam(required = false) Integer plat, @RequestParam(required = false) String keyword) {
		return ResultDTO.success(super.getAllChannelListByPermit(plat, keyword, GlobalConsts.LEVEL_1, null));
	}

	/**
	 * 通过渠道大类获取渠道列表
	 *
	 * @param channelTypeId 渠道大类ID
	 * @return 渠道大类下的渠道列表
	 */
	@RequestMapping(value = "/listById", method = RequestMethod.GET)
	@ResponseBody
	public ResultDTO listById(@RequestParam(name = "channelTypeId") Integer channelTypeId) {
		return ResultDTO.success(super.listChannelByTypeId(channelTypeId));
	}

	/**
	 * 根据厂商ID获取渠道ID
	 * @param factoryId
	 * @return
	 * @throws OmsBaseException
	 */
	@RequestMapping(value = "/getChannelIdByFactoryId", method = RequestMethod.GET)
	@ResponseBody
	public ResultDTO getChannelIdByFactoryId(@RequestParam(name = "factoryId") Integer factoryId) throws OmsBaseException {
		// 渠道ID
		/*ResponseDTO<FactoryDRO> responseDTO = factoryListRemoteService.getFactoryById(factoryId);
		if (responseDTO.getData() == null) {
			throw new OmsBaseException(responseDTO.getMessage());
		}
		return ResultDTO.success(responseDTO.getData().getChannelId());*/
		return ResultDTO.fail("厂商服务已下线");
	}



}
